<template>
  <div>
    <div>
      <el-form label-width="100px" size="mini">
        <el-row :gutter="40">
          <el-col :span="8">
            <el-form-item label="任务名称：">
              <span>{{ formItem.name }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="任务编码：">
              <span>{{ formItem.code }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="任务责任人：">
              <span>{{ formItem.userName }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="40">
          <el-col v-if="formItem.locations.length > 0" :span="24">
            <el-form-item label="盘点位置：">
              <span v-for="(m,i) in formItem.locations" :key="i"><el-tag>{{ m.name }}</el-tag></span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="40">
          <el-col v-if="formItem.orgRelation.length > 0" :span="24">
            <el-form-item label="盘点部门：">
              <span v-for="(m,i) in formItem.orgRelation" :key="i"><el-tag>{{ m.name }}</el-tag></span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="40">
          <el-col v-if="formItem.assetTypes.length > 0" :span="24">
            <el-form-item label="盘点类型：">
              <span v-for="(m,i) in formItem.assetTypes" :key="i"><el-tag>{{ m.name }}</el-tag></span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import {
  detail
} from '@neu/dcam-ui/api/inventoryDuty'

export default {
  name: 'ShowScopeForm',
  props: {
    // 根据id可判断是新建还是更新
    id: {
      required: false,
      type: Number,
      default: -1
    }
  },
  data() {
    return {
      formItem: {
        name: '',
        code: '',
        userName: '',
        locations: [],
        orgRelation: [],
        assetTypes: []
      }
    }
  },
  watch: {
    // 监控id的变化，初始化表单数据
    id: {
      handler(newVal, oldVal) {
        this.fetch()
      },
      immediate: true
    }
  },
  created() {
  },
  methods: {
    // 初始化表单数据
    fetch() {
      if (this.id !== -1) {
        detail(this.id).then(response => {
          this.formItem = {
            ...response.data
          }
        })
      }
    }
  }
}
</script>
